package yy.robot.service;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.stereotype.Service;
import yy.robot.domain.Strategy;
import yy.robot.repository.StrategyRepository;

/**
 * Created by BaiJiFeiLong@gmail.com at 2018/5/7 11:19
 */
@Service
public class StrategyService {

    @Autowired
    private StrategyRepository strategyRepository;

    public Page<Strategy> findAll(Pageable pageable) {
        return strategyRepository.findAll(pageable);
    }

    public Strategy findById(long id) {
        return strategyRepository.findById(id).get();
    }

    public Strategy create(Strategy strategy) {
        strategyRepository.save(strategy);
        return strategy;
    }

    public Strategy update(Strategy strategy) {
        strategyRepository.save(strategy);
        return strategy;
    }

    public void destroy(long id) {
        strategyRepository.deleteById(id);
    }
}
